package cn.tqfeiyang.smartadmin.business.organization.controller;

import cn.tqfeiyang.smartadmin.business.organization.constant.EmployeeConstants;
import cn.tqfeiyang.smartadmin.business.organization.service.EmployeeExcelService;
import cn.tqfeiyang.smartadmin.business.organization.request.EmployeeQueryDTO;

import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.multipart.MultipartFile;
import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import cn.tqfeiyang.smartadmin.commons.response.ApiResult;
import cn.tqfeiyang.smartadmin.commons.logging.OperationLog;

/**
 * 员工Excel控制器
 *
 * @author tqfeiyang
 * @since 2024-10-18
 */
@RestController
@Validated
@RequestMapping(EmployeeConstants.REQUEST_URL)
@Tag(name = EmployeeConstants.API_TAG)
public class EmployeeExcelController {

    /**
     * 员工Excel服务
     */
    @Resource
    private EmployeeExcelService employeeExcelService;

    /**
     * 导出员工Excel
     */
    @OperationLog
    @GetMapping("/exportEmployeesToExcel")
    @Operation(summary = "员工 - 导出员工Excel")
    @SaCheckPermission(EmployeeConstants.PERMISSION + "exportEmployeesToExcel")
    public void exportEmployeesToExcel(@Validated EmployeeQueryDTO dto) {
        employeeExcelService.exportEmployeesToExcel(dto);
    }

    /**
     * 下载员工模板
     */
    @OperationLog
    @GetMapping("/downloadEmployeeTemplate")
    @Operation(summary = "员工 - 下载员工模板")
    @SaCheckPermission(EmployeeConstants.PERMISSION + "downloadEmployeeTemplate")
    public void downloadEmployeeTemplate() {
        employeeExcelService.downloadEmployeeTemplate();
    }

    /**
     * 导入员工Excel
     */
    @OperationLog
    @PostMapping("/importEmployeesFromExcel")
    @Operation(summary = "员工 - 导入员工Excel")
    @SaCheckPermission(EmployeeConstants.PERMISSION + "importEmployeesFromExcel")
    public ApiResult importEmployeesFromExcel(MultipartFile file) {
        employeeExcelService.importEmployeesFromExcel(file);
        return ApiResult.success();
    }
}
